﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TaskManagement.Context;
using TaskManagement.Jobs;
using TaskManagement.Model;
using TaskManagement.Utils;

namespace TaskManagement.Service
{
    public static class TaskService
    {
        public static List<int> taskIds = new List<int>();
        public static void start()
        {
            var db = new DbFactory().GetDbContext();
            var tasks = db.Queryable<TASK>().ToList();
            for(var i=0;i< tasks.Count; i++)
            {
                startSingleTask(tasks[i]);
            }
            
        }

        private static void startSingleTask(TASK task)
        {
            
            if (task.TYPE == "ping")
            {
                var pingJob = QuartzHelpers.StartAsync<PingJob>(new TimeSpan(0, 0, task.TIMESPAN), "job_" + task.ID, "trigger_" + task.ID, "pingGroup", task.NAME);
                taskIds.Add(task.ID);


            }
            else if (task.TYPE == "telnet")
            {
                var telnetJob = QuartzHelpers.StartAsync<TelnetJob>(new TimeSpan(0, 0, task.TIMESPAN), "job_" + task.ID, "trigger_" + task.ID, "telnetGroup", task.NAME);
                taskIds.Add(task.ID);

            }
        }
    }
}
